import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};

const Home = () => import('views/Home.vue')
const FindMusic = () => import('views/home/findMusic/FindMusic.vue')
const DiyRecommend = () => import('views/home/findMusic/recommend/DiyRecommend.vue')
const SongList = () => import('views/home/findMusic/songList/SongList.vue')
const Rank = () => import('views/home/findMusic/rank/Rank.vue')
const SingerList = () => import('views/home/findMusic/singerList/SingerList.vue')
const NewMusic = () => import('components/findMusic/newMusic/NewMusic.vue')

const Veido = () => import('views/home/veido/Veido.vue')
const MvDetail = () => import('views/home/veido/MvDetail.vue')
const VideoDetail = () => import('views/home/veido/VideoDetail.vue')

const AlbumDetail = () => import('components/content/AlbumDetail.vue')
const SearchList = () => import('components/content/SearchList.vue')
const SingerDetail = () => import('components/content/SingerDetail.vue')
const UserInfo = () => import('components/content/UserInfo.vue')
const UserFollows = () => import('components/content/UserFollows.vue')
const UserFolloweds = () => import('components/content/UserFolloweds.vue')
const UserEdit = () => import('components/content/UserEdit.vue')


const SongListPage = () => import('views/home/songListPage/SongListPage.vue')

const RecommendPlay = () => import('components/leftNav/RecommendPlay.vue')
const MyCloud = () => import('components/leftNav/MyCloud.vue')
const MyCollect = () => import('views/home/leftNav/myCollect/MyCollect.vue')
const MyEvent = () => import('views/home/leftNav/myEvent/MyEvent.vue')
const UserEvent = () => import('components/leftNav/myEvent/UserEvent.vue')




const routes = [{
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    redirect: '/findMusic',
    children: [
      //发现音乐板块
      {
        path: '/findMusic',
        name: 'findMusic',
        component: FindMusic,
        redirect: '/diyRecommend',
        children: [
          //个性推荐
          {
            path: '/diyRecommend',
            component: DiyRecommend
          },
          //歌单
          {
            path: "/songList",
            component: SongList
          },
          //排行榜
          {
            path: "/rank",
            component: Rank
          },
          //歌手榜
          {
            path: '/singerList',
            component: SingerList
          },
          //最新音乐
          {
            path: '/newMusic',
            component: NewMusic
          }

        ]
      },
      //歌单详情板块
      {
        path: '/songListPage/:id',
        component: SongListPage
      },
      //mv板块
      {
        path: '/veido',
        component: Veido
      },
      //视频详情
      {
        path: "/videoDetail/:id",
        component: VideoDetail
      },
      //mv详情
      {
        path: '/mvDetail/:id',
        component: MvDetail
      },
      //歌手专辑
      {
        path: '/albumDetail/:id',
        component: AlbumDetail
      },
      //搜索列表
      {
        path: '/searchList/:data',
        component: SearchList
      },
      //歌手详情
      {
        path: '/singerDetail/:id',
        component: SingerDetail,
      },
      //最近播放
      {
        path: '/recommendPlay/',
        component: RecommendPlay
      },
      {
        path: '/myCloud',
        component: MyCloud
      },
      //个人信息
      {
        path: "/userInfo/:id",
        name: 'userinfo',
        component: UserInfo
      },
      //用户关注
      {
        path: "/userFollows/:id",
        component: UserFollows
      },
      //用户粉丝
      {
        path: "/userFolloweds/:id",
        component: UserFolloweds
      },
      //用户编辑
      {
        path: '/userEdit/:id',
        component: UserEdit
      },
      //用户收藏
      {
        path: '/myCollect',
        component: MyCollect
      },
      //动态展示
      {
        path: '/myEvent',
        component: MyEvent
      },
      //好友动态
      {
        path:'/userevent/:id',
        component:UserEvent
      }
    ]
  },

]

const router = new VueRouter({
  routes,
  mode: "history"
})

export default router
